﻿using System;
using System.Collections.Generic;
using System.Linq;
using LINQPad.OpenAccess.Helpers;
using Telerik.OpenAccess.Metadata;
using Telerik.OpenAccess.Metadata.Fluent;

namespace LINQPad.OpenAccess.Metadata
{
    /// <summary>
    /// MetadataSource - extensions.
    /// </summary>
    public static class MetadataSourceExtensions
    {
        /// <summary>
        /// Gets the type of the mapping definition for the specified metadata source.
        /// </summary>
        /// <param name="metadataSource">The metadata source.</param>
        /// <returns></returns>
        /// <exception cref="System.ArgumentNullException">metadataSource</exception>
        /// <exception cref="System.NotSupportedException">if <paramref name="metadataSource"/> is not supported.</exception>
        public static MappingDefinitionType GetMappingDefinitionType( this MetadataSource metadataSource )
        {
            Guard.ArgumentNotNull( metadataSource, "metadataSource" );

            if ( metadataSource is FluentMetadataSource )
                return MappingDefinitionType.Fluent;
            else if ( metadataSource is AttributesMetadataSource )
                return MappingDefinitionType.Attributes;
            else if ( metadataSource is XmlMetadataSourceBase )
                return MappingDefinitionType.Xml;
            else if ( metadataSource is AggregateMetadataSource )
                return MappingDefinitionType.Combined;

            throw new NotSupportedException( String.Format( "Unknown metadata source type '{0}' !", metadataSource.GetType( ).FullName ) );
        }

    }
}